
	class Phonebook {
		
		private Contact[] contactlist;
		
		
		public Phonebook(int i){
			contactlist = new Contact[i];
		}
		
		
		public String addContact(Contact c){//Add Contact
			for(int i = 0;i <= contactlist.length - 1;i++){	//Search for space in phonebook
				if(checkNull(i)){
					contactlist[i] = c;
					return ("Contact added successfully");
				}
				else if(i == contactlist.length - 1){	//If there's no space in phonebook
					return ("Contact not added - phonebook full");
				}
				}
			return ("");
		}
			
		
		
		public String getContactFirstName(int i){//Return contact first name
			return contactlist[i].getFirstName();
		}
		
		public String getContactSecondName(int i){//Return contact second name
			return contactlist[i].getSecondName();
		}
		
		public String getContactNumber(int i){	//Return contact phone number
			return contactlist[i].getNumber();
		}
		
		public String getContactAddress(int i){	//Return contact address
			return contactlist[i].getAddress();
		}
		
		public String getContactDetails(int i){	//Return all contact details
			if(!checkNull(i)){
				return ("Entry #" + (i+1) + "\n\n" + contactlist[i].getDetails()); //Returns entry number and contact details
			}
			else{
				return("Invalid Selection");//Message returned if a non-existing entry number is used
			}
		}
		
		
		public int getSize(){//Get size of phone book by getting array length
			return contactlist.length;
		}
		
		
		public boolean checkNull(int i){//Check to make sure an element in the phonebook is not null
			return ((contactlist.length - 1 < i) || contactlist[i] == null);
		}
		
		
		public String deleteContact(int i){
			if(!checkNull(i)){
			contactlist[i] = null;
			return ("Contact Deleted");		//Message returned if contact successfully deleted
			}
			else{
				return ("Entry Number Invalid - Contact Does Not Exist"); //Message returned if a non-existing entry number was used
			}
		}
		
		
		
		public Contact[] search(String option,String search){
			Contact[] result = new Contact[contactlist.length];	//Search result array is size of maximum possible amount of results
			int resultscheck = 0;
				for(int i = 0;i<=contactlist.length - 1;i++){
					if(!checkNull(i)){
						/*Program compares the search to an attribute of a contact, depending on the search option chosen by user*/
					if((option.equals("1") && search.equalsIgnoreCase(contactlist[i].getFirstName())) || (option.equals("2") && search.equalsIgnoreCase(contactlist[i].getSecondName())) || (option.equals("3") && search.equalsIgnoreCase(contactlist[i].getNumber())) || (option.equals("4") && search.equalsIgnoreCase(contactlist[i].getAddress()))) {
						result[i] = new Contact(contactlist[i].getFirstName(),contactlist[i].getSecondName(),contactlist[i].getNumber(),contactlist[i].getAddress());
						resultscheck++;
					}
					}
					}
				if(resultscheck >= 1){
				return result;
				}
				else{
					return null;
				}
		}

}
